#ifndef __CLIENT_CACHE__
#define __CLIENT_CACHE__

#include "utility.h"

class ClientCache {
public:

	ClientCache(): hit_cnt(0), set_cnt(0) {}

	void set_cache(int index, const char* cache, int size) {
		memcpy(buffer[index], cache, size);
		set_cnt++;
	}

	void use_cache(int index) {
		cur_ptr = buffer[index];
		hit_cnt++;
	}

	////////////////////////////////////////////////////////////////////////
	//read regular data

	int read_int() {
#ifdef USE_VARINT
		int data;
		Compressor::decode_int(cur_ptr, data);
		return data;
#else
		int data = *( (int*)(cur_ptr) );
		cur_ptr += sizeof(int);
		return data;
#endif
	}

	UINT read_uint() {
#ifdef USE_VARINT
		UINT data;
		Compressor::decode_uint(cur_ptr, data);
		return data;
#else
		UINT data = *( (UINT*)(cur_ptr) );
		cur_ptr += sizeof(UINT);
		return data;
#endif
	}

	char read_char() {
		char data = *( (char*)(cur_ptr) );
		cur_ptr += sizeof(char);
		return data;
	}

	UCHAR read_uchar() {
		UCHAR data = *( (UCHAR*)(cur_ptr) );
		cur_ptr += sizeof(UCHAR);
		return data;
	}

	float read_float() {
		float data = *( (float*)(cur_ptr) );
		cur_ptr += sizeof(float);
		return data;
	}

	short read_short() {
		short data = *( (short*)(cur_ptr) );
		cur_ptr += sizeof(short);
		return data;
	}

	USHORT read_ushort() {
		USHORT data = *( (USHORT*)(cur_ptr) );
		cur_ptr += sizeof(USHORT);
		return data;
	}

	void read_byte_arr(char* dst, int length) {
		memcpy(dst, cur_ptr, length);
		cur_ptr += length;
	}

private:
	char buffer[301][100];
	char* cur_ptr;
public:
	int set_cnt, hit_cnt;
};



#endif
